extends Resource
class_name BufferState

var value: int = 0
var duration: int = 0
@export var show_duration: bool = false
@export var show_value: bool = true

@export var icon: Texture
@export var state_scene: PackedScene

@export var id: StateBar.STATE

var tooltip_text = ""
var tooltip_text_str = ""

func create_instance(v, d) -> Resource:
	var instance: BufferState = self.duplicate()
	instance.value = v
	instance.duration = d
	return instance

#用于状态的生效
func before_round(_target):
	pass

#用于状态的减少
func after_round(_target):
	pass


func before_free(_target):
	pass

func update_tooltip_text(_value, _duration):
	if tooltip_text.contains("%s") :
		tooltip_text_str = tooltip_text % [str(_value)]
	else:
		tooltip_text_str = tooltip_text 

func init_scene() -> Node:
	if Globals.STATE_INTRODUCE_DIR.has(str(self.id)):
		var introduce = Globals.STATE_INTRODUCE_DIR[str(self.id)]
		tooltip_text = introduce[1]
		update_tooltip_text(value, duration)
	var s = state_scene.instantiate()
	s.state = self
	return s
